/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.util.List;
import model.pojo.Dealer;
import model.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author DucThien
 */
public class dealerDAO extends AbstractDAO<Dealer, String>  {

    @Override
    protected Class getPOJOClass() {
        return Dealer.class;
    }
    
    public  Dealer getDealerByDealerID(int dealer_id){
        List<Dealer> list = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try{
            String hql = "FROM Dealer dl WHERE dl.dealerId=:dealerID";
            Query query = session.createQuery(hql);
            query.setInteger("dealerID", dealer_id);
            list = query.list();
            if(list.isEmpty() == true){
                return null;
            }
        }catch(HibernateException ex){
            System.err.println(ex);
        }finally{
            session.close();
        }        
        return list.get(0);
    }
}
